package com.lcx.plugin.dto;

import cn.hutool.json.JSONUtil;
import com.lcx.plugin.entity.TypeMapper;
import com.lcx.plugin.enums.FieldMatchType;
import com.lcx.plugin.enums.MysqlTypeMatch;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * 设置储存传输对象
 *
 * @author daxiong
 * @date 2023/6/19 上午10:32
 */
@Data
public class MySettingsStorageDTO {

    /**
     * 模板下载路径
     */
    private String templateDownloadPath;
    /**
     * 列序号配置
     */
    private ColumnIndexDTO columnIndexDTO;
    /**
     * 默认记住密码
     */
    private boolean rememberPwd = true;
    /**
     * 默认合并名称和备注
     */
    private boolean mergeNameMemo = true;

    /**
     * 类型映射列表
     */
    private List<TypeMapper> elementList;

    /**
     * 返回默认值，不使用静态常量，防止默认值别篡改
     *
     * @return 储存对象
     */
    public static MySettingsStorageDTO defaultVal() {
        // 直接创建配置
        MySettingsStorageDTO storage = new MySettingsStorageDTO();
        storage.setTemplateDownloadPath("");
        Map<String, Integer> fieldDefIndexMap = FieldMatchType.getFieldDefIndexMap();
        ColumnIndexDTO columnIndexDTO = JSONUtil.toBean(JSONUtil.parseObj(fieldDefIndexMap), ColumnIndexDTO.class);
        storage.setColumnIndexDTO(columnIndexDTO);
        storage.setMergeNameMemo(true);
        storage.setRememberPwd(true);
        storage.setElementList(MysqlTypeMatch.defaultValues());
        return storage;
    }

    /**
     * 重置为默认值
     */
    public MySettingsStorageDTO resetDefaultVal() {
        return defaultVal();
    }

}
